package com.zucc.controller;

import com.zucc.controller.req.*;
import com.zucc.controller.resp.DictItemResp;
import com.zucc.controller.resp.DictResp;
import com.zucc.service.DictService;
import com.zucc.service.base.PageData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : charspan
 * @Description :
 * @create : 2021-12-02 5:59 下午
 */
@RestController
@Slf4j
@RequestMapping("/v1/api/dicts")
@Api(tags = "字典管理")
public class DictController {

    @Resource
    private DictService dictService;

    @ApiOperation(value = "新增字典(开发过程使用，开发完成不需要使用的接口)")
    @PostMapping
    void add(@RequestBody @Validated DictAddReq req) {
        dictService.add(req);
    }

    @ApiOperation(value = "字典分页")
    @PostMapping("/page")
    PageData<DictResp> page(@RequestBody @Validated DictSearchReq req) {
       return dictService.page(req);
    }

    @ApiOperation(value = "新增字典项")
    @PostMapping("/items")
    void addDictItem(@RequestBody @Validated DictItemAddReq req) {
        dictService.addDictItem(req);
    }

    @ApiOperation(value = "修改字典项")
    @PutMapping("/items")
    void modifyDictItem(@RequestBody @Validated DictItemModifyReq req) {
        dictService.modifyDictItem(req);
    }

    @ApiOperation(value = "删除字典项")
    @ApiImplicitParam(paramType = "path", name = "id", value = "字典项编号", dataType = "Long", example = "1", required = true)
    @DeleteMapping("/items/{id}")
    void deleteOne(@PathVariable Long id) {
        dictService.deleteOne(id);
    }

    @ApiOperation("批量删除字典项")
    @DeleteMapping("/items")
    void deleteMulti(@RequestBody @Validated Ids req) {
        dictService.deleteMulti(req);
    }

    @ApiOperation(value = "字典项列表")
    @ApiImplicitParam(paramType = "path", name = "id", value = "字典编号", dataType = "Long", example = "1", required = true)
    @PostMapping("/{id}/list")
    List<DictItemResp> getDictItemList(@PathVariable Long id) {
        return dictService.getDictItemList(id);
    }
}
